/**
 * 
 */
package com.gmail.blackdog1987.onedollar.web.controller;

import com.gmail.blackdog1987.onedollar.service.LuckyBagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 
 * @author 董国超
 *
 */
@Controller
public class LuckyBagController extends BaseController {
	@Autowired
	private LuckyBagService luckyBagService;

	/**
	 * 发送红包
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="sendLuckyBag", method=RequestMethod.POST)
	public Map<String, Object> sendLuckyBag(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = luckyBagService.doSend(filter);
		return decorateResult(result);
	}

	/**
	 * 领取红包
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="consumeLuckyBag", method=RequestMethod.POST)
	public Map<String, Object> consumeLuckyBag(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = luckyBagService.doConsume(filter);
		return decorateResult(result);
	}

	/**
	 * 查询我的红包列表
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getMyLuckyBag", method=RequestMethod.POST)
	public Map<String, Object> getMyLyckyBag(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = luckyBagService.getList(filter);
		return decorateResult(result);
	}

	/**
	 * 获取我可以领取的红包列表
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getMyNewLuckyBag", method=RequestMethod.POST)
	public Map<String, Object> getMyNewLuckyBag(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = luckyBagService.getNewList(filter);
		return decorateResult(result);
	}

	/**
	 * 获取最新的红包数量
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="hasNewLuckyBag", method=RequestMethod.POST)
	public Map<String, Object> hasNewLuckyBag(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = luckyBagService.getNewCount(filter);
		return decorateResult(result);
	}

	/**
	 * 获取最新的红包（领取）
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getNewLuckyBag", method=RequestMethod.POST)
	public Map<String, Object> getNewLuckyBag(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = luckyBagService.getNew(filter);
		return decorateResult(result);
	}

	/**
	 * 根据年获取红包概述
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getLuckyBagYear", method=RequestMethod.POST)
	public Map<String, Object> getLuckyBagYear(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = luckyBagService.getLuckyBagYear(filter);
		return decorateResult(result);
	}

	@Override
	protected Map<String, Object> decorateResult(Map<String, Object> result) {
		result.put("time", System.currentTimeMillis());
		return result;
	}
}
